package com.loans.product.controller;

import com.loans.product.domain.TbLocantype;
import com.loans.product.service.ITbLocantypeService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 贷款类型Controller
 * 
 * @author ruoyi
 * @date 2022-12-12
 */
@RestController
@RequestMapping("/locantype")
public class TbLocantypeController extends BaseController
{
    @Autowired
    private ITbLocantypeService tbLocantypeService;

    /**
     * 查询贷款类型列表
     */
    @RequiresPermissions("product:locantype:list")
    @GetMapping("/list")
    public TableDataInfo list(TbLocantype tbLocantype)
    {
        startPage();
        List<TbLocantype> list = tbLocantypeService.selectTbLocantypeList(tbLocantype);
        return getDataTable(list);
    }

    /**
     * 导出贷款类型列表
     */
    @RequiresPermissions("product:locantype:export")
    @Log(title = "贷款类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbLocantype tbLocantype)
    {
        List<TbLocantype> list = tbLocantypeService.selectTbLocantypeList(tbLocantype);
        ExcelUtil<TbLocantype> util = new ExcelUtil<TbLocantype>(TbLocantype.class);
        util.exportExcel(response, list, "贷款类型数据");
    }

    /**
     * 获取贷款类型详细信息
     */
    @RequiresPermissions("product:locantype:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tbLocantypeService.selectTbLocantypeById(id));
    }

    /**
     * 新增贷款类型
     */
    @RequiresPermissions("product:locantype:add")
    @Log(title = "贷款类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbLocantype tbLocantype)
    {
        return toAjax(tbLocantypeService.insertTbLocantype(tbLocantype));
    }

    /**
     * 修改贷款类型
     */
    @RequiresPermissions("product:locantype:edit")
    @Log(title = "贷款类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbLocantype tbLocantype)
    {
        return toAjax(tbLocantypeService.updateTbLocantype(tbLocantype));
    }

    /**
     * 删除贷款类型
     */
    @RequiresPermissions("product:locantype:remove")
    @Log(title = "贷款类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbLocantypeService.deleteTbLocantypeByIds(ids));
    }
}
